package class1;

import com.mysql.MysqlMethod;
import student.list.studentlist.StudentListView;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 查询班级列表
 */
@WebServlet("/class1/list")
public class ClassListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");//转码
        String pageNum = req.getParameter("pageNum");
        if (pageNum == null || "".equals("pageNum")) {
            pageNum = "1";
        }
        String pageSize = req.getParameter("pageSize");
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = "10";
        }
        String classNo = req.getParameter("classNo");
        String name = req.getParameter("name");
       //Integer pageNum1 = Integer.valueOf(pageNum);
       // String type1 = req.getParameter("type");
        StudentListView studentListView = new StudentListView();
        studentListView.setCode(0);//code为0说明请求成功
        studentListView.setMsg("success");
        studentListView.setTotal(6);//设置要传递的参数的个数
        //拼接数据,使其变为json格式
        String arr2 = "{\"code\":0,\"msg\":\"success\",\"rows\":"+ MysqlMethod.selectClassAll(pageNum,pageSize,classNo,name)+",\"total\":6}";
        //往前端发送数据
        resp.getWriter().write(arr2);
    }
}
